package com.yyfax.pay.third.model.to.quickpay;

import org.apache.commons.lang3.StringUtils;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.yyfax.framework.exception.YYException;
import com.yyfax.framework.yyfax.enums.RspCodeEnum;
import com.yyfax.pay.third.model.to.quickpay.xml.GetDynNumContent;

/**
 * 获取验证码参数
 * 
 * @author xiemh
 * @date 2016-09-27 14:57:25
 * @since v1.0.0
 */
@SuppressWarnings("serial")
@XStreamAlias("MasMessage")
public class SendVerifyCodeQuickPayParams extends BaseQuickPayParams {
	private String version = "1.0";

	@XStreamAlias("GetDynNumContent")
	private GetDynNumContent getDynNumContent;

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public GetDynNumContent getGetDynNumContent() {
		return getDynNumContent;
	}

	public void setGetDynNumContent(GetDynNumContent getDynNumContent) {
		this.getDynNumContent = getDynNumContent;
	}

	/**
	 * 通过xml生成实体类
	 * 
	 * @author xiemh
	 * @date 2017-04-12 14:51:24
	 * @since v1.0.0
	 * @param xml
	 * @return
	 */
	public static SendVerifyCodeQuickPayParams fromXml(String xml) throws Exception {
		return (SendVerifyCodeQuickPayParams) fromXml(xml, SendVerifyCodeQuickPayParams.class);
	}

	@Override
	public boolean validate() throws Exception {


		if (StringUtils.isBlank(getDynNumContent.getAmount())) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_REQUIRED, "amount");
		}
		if (StringUtils.isBlank(getDynNumContent.getCustomerId())) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_REQUIRED, "customerId/userId");
		}
		if (StringUtils.isBlank(getDynNumContent.getExternalRefNumber())) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_REQUIRED, "externalRefNumber/orderId");
		}

		if (StringUtils.isBlank(getDynNumContent.getStorablePan()) && StringUtils.isBlank(getDynNumContent.getPan())) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_REQUIRED, "pan/cardNo ");
		}

		return true;
	}

}
